/*
 * @Author: LGX
 * @Date: 2022-03-30 17:57:54
 * @LastEditors: LGX
 * @LastEditTime: 2022-04-11 20:16:03
 * @FilePath: \erp-management-system\src\components\customerseas\Pagination.jsx
 * @Description: 下方分页
 * 
 */
import React, { useState } from 'react'
import moment from 'moment'
import { Pagination, Row, Col, Select, Modal, Space, message } from 'antd'
import MyButton from '../customerseas/MyButton'
import axios from '../../utils/http'
const { Option } = Select;



export default function Paginations(props) {
    const { customerList, setPagination, selectTable, setselectTable } = props
    const [receiveObj, setreceiveObj] = useState();
    const [isModalVisible, setModalVisible] = useState(false);
    const [isModalDele, setModalDele] = useState(false);
    // console.log(selectTable);
    //下拉框
    function onChange(value) {
        setreceiveObj(value)
    }
    function onSearch(val) {
        console.log('search:', val);

    }
    //通过审核 /拒绝申请
    const getAudit = (status) => {
        if (!selectTable) {
            message.error('请至少勾选一个客户')
        } else {
            console.log(status, selectTable);
            axios({
                url: '/gongHai/applyPublicCustomerById',
                method: 'post',
                headers: {
                    isLoading: false
                },
                data: {
                    applyPerson: "超级管理员",
                    applyStatus: status,
                    applyTime: status == 1 ? moment(new Date()).format('YYYY-MM-DD h:mm:ss') : '',
                    idList: selectTable,
                    updateTime: status == 0 || status == 2 ? moment(new Date()).format('YYYY-MM-DD h:mm:ss') : '',
                }
            }).then(res => {
                console.log(res);
                if (res.data.code === 200) {
                    if (status == 1) {
                        message.success('申请成功')
                    }
                    else if (status == 0) {
                        message.success('已拒绝申请')
                    }
                    else if (status == 2) {
                        message.success('审核通过')
                    }
                    setselectTable([])
                }
                else if (JSON.stringify(res.data) === '{}') {
                    message.error('当前客户未被申请，不能操作')
                }
            })
        }
    }
    //转移
    const transfer = () => {
        if (!selectTable) {
            message.warning('请选中要转移的客户')
        } else {
            if (!receiveObj) {
                message.warning('请选择要转移给的对象')
            } else {
                //发起请求
                axios({
                    url: '',
                    method: 'post',
                    data: {}
                }).then(res => {
                    console.log(res);
                })
            }
            console.log(selectTable);
        }

    }
    //删除至回收站
    const delet = () => {
        if (!selectTable) {
            message.error('请至少勾选一个客户')
        } else {
            axios({
                url: '/gongHai/batchDeletePublicCustomerByIdList',
                method: 'post',
                data: selectTable
            }).then(res => {
                message.success(res.data.msg)
                setModalVisible(false)
                setselectTable([])
            })
        }
    }
    function handleCancel() {
        setModalVisible(false)
    }
    //清除公海所有数据
    const delAll = () => {
        axios({
            url: '/gongHai/clearPublicCustomer',
            method: 'post',
            data: selectTable
        }).then(res => {
            if (res.data.code == 200) {
                message.success(res.data.msg)
                setTimeout(() => {
                    setModalDele(false)
                }, 1500)
            }
        })
    }
    function handleCancelAll() {
        setModalDele(false)
    }
    function pageSize(currentPage, pageSize) {
        // console.log(currentPage +  1, pageSize);
        setPagination({ currentPage: currentPage == 0 ? currentPage + 1 : currentPage, pageSize, status: '1' })
    }
    return (

        <Row justify='end' align='center' style={{ marginTop: '30px' }}>
            <Col span={14}>
                <Space size={2}>
                    <span>将选中的信息批量:</span>
                    <MyButton color='#338841' onClick={() => getAudit(2)} title='通过审核' />
                    <MyButton color='#626061' onClick={() => getAudit(0)} title='拒绝申请' />
                    <span>转移给:</span>
                    <Select
                        showSearch
                        placeholder="请选择"
                        optionFilterProp="children"
                        onChange={onChange}
                        onSearch={onSearch}
                        filterOption={(input, option) =>
                            option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                        }
                    >
                        <Option value="jack">Jack</Option>
                        <Option value="lucy">Lucy</Option>
                        <Option value="tom">Tom</Option>
                    </Select>
                    <MyButton color='#486b7b' onClick={transfer} title='转移' />
                    <MyButton color='#434443' onClick={() => {
                        if (!selectTable) {
                            message.error('请至少勾选一个客户')
                        } else {
                            setModalVisible(true)
                        }
                    }} title='删除至回收站' />
                    <MyButton color='#cfcdcd' onClick={() => { setModalDele(true) }} title='清除公海所有数据' />

                </Space>
                {/* 移入回收站 */}
                <Modal title="移入回收站" visible={isModalVisible} onOk={delet} onCancel={handleCancel}>
                    <p>移入回收站后，可在回收站中恢复，是否继续?</p>
                </Modal>
                {/* 清空所有客户公海 */}
                <Modal title="即将清空左右客户公海" visible={isModalDele} onOk={delAll} onCancel={handleCancelAll}>
                    <p>一旦删除不可恢复，请谨慎操作</p>
                </Modal>
            </Col>
            <Col span={10} style={{ textAlign: 'right' }}>
                <Pagination
                    total={customerList.count}
                    showSizeChanger
                    showQuickJumper
                    pageSizeOptions={[5,10, 15, 20, 25]}
                    defaultCurrent={1}
                    defaultPageSize={10}
                    showTotal={total => `总数 ${total} 条`}
                    onChange={pageSize}
                />
            </Col>

        </Row>
    )
}
